package com.getpebble.android.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Trace;
import com.getpebble.android.common.model.ConnectionGoal;
import com.getpebble.android.common.model.ConnectionStatus;
import com.getpebble.android.common.model.PblDeviceModel.PblDeviceRecord;
import com.getpebble.android.common.model.PebbleColor;
import com.sun.mail.iap.Response;
import com.sun.mail.imap.protocol.ListInfo;
import com.sun.mail.smtp.SMTPMessage;

public class PblDeviceView extends LinearLayout {
    private static final String TAG = PblDeviceView.class.getSimpleName();
    private ImageView mConnectionImage = ((ImageView) findViewById(R.id.pbl_connection_img));
    private PblDeviceRecord mDevice;
    private TextView mInfoView = ((TextView) findViewById(R.id.pbl_info));
    private TextView mNameView = ((TextView) findViewById(R.id.pbl_name));
    private TextView mStatusView = ((TextView) findViewById(R.id.pbl_connection_status));
    private TextView mTapToDisconnectView = ((TextView) findViewById(R.id.tap_to_disconnect_cancel));

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$common$model$ConnectionStatus = new int[ConnectionStatus.values().length];
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$common$model$PebbleColor = new int[PebbleColor.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_BLACK.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_WHITE.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_RED.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_ORANGE.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_GRAY.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_BIANCA_SILVER.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_BIANCA_BLACK.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_TINTIN_BLUE.ordinal()] = 8;
            } catch (NoSuchFieldError e8) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_TINTIN_GREEN.ordinal()] = 9;
            } catch (NoSuchFieldError e9) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$PebbleColor[PebbleColor.COLOR_TINTIN_PINK.ordinal()] = 10;
            } catch (NoSuchFieldError e10) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$ConnectionStatus[ConnectionStatus.CONNECTED.ordinal()] = 1;
            } catch (NoSuchFieldError e11) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$ConnectionStatus[ConnectionStatus.CONNECTING.ordinal()] = 2;
            } catch (NoSuchFieldError e12) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$ConnectionStatus[ConnectionStatus.UNKNOWN.ordinal()] = 3;
            } catch (NoSuchFieldError e13) {
            }
            try {
                $SwitchMap$com$getpebble$android$common$model$ConnectionStatus[ConnectionStatus.DISCONNECTED.ordinal()] = 4;
            } catch (NoSuchFieldError e14) {
            }
        }
    }

    public PblDeviceView(Context context) {
        super(context);
        View rootView = LayoutInflater.from(context).inflate(R.layout.view_pbl_device, this, true);
    }

    public void setDevice(PblDeviceRecord device) {
        this.mDevice = device;
        if (this.mDevice == null) {
            Trace.debug(TAG, "Cannot update() with no model");
            return;
        }
        if (this.mNameView != null) {
            this.mNameView.setText(this.mDevice.pblDevice.getName());
        } else {
            Trace.debug(TAG, "Cannot set name, view is null");
        }
        if (this.mConnectionImage != null) {
            Drawable drawable = getConnectionDrawableForColor(getContext(), this.mDevice.color);
            if (drawable != null) {
                this.mConnectionImage.setImageDrawable(drawable);
            }
        }
        if (this.mInfoView != null) {
            String infoText;
            if (this.mDevice.lastConnectedTimeMillis == 0) {
                infoText = getResources().getString(R.string.connection_manager_new_pebble);
            } else {
                infoText = String.format(getResources().getString(R.string.connection_manager_watch_version), new Object[]{this.mDevice.fwVersion});
            }
            this.mInfoView.setText(infoText);
        } else {
            Trace.debug(TAG, "Cannot set info view, view is null");
        }
        this.mStatusView.setText(getStringForConnectionStatus(this.mDevice));
        this.mStatusView.setTextColor(getResources().getColor(getTextColourResourceIdForConnectionStatus(this.mDevice)));
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$common$model$ConnectionStatus[this.mDevice.connectionStatus.ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                if (this.mNameView != null) {
                    this.mNameView.setTextColor(getResources().getColor(R.color.white));
                }
                if (this.mConnectionImage != null) {
                    this.mConnectionImage.setAlpha(1.0f);
                }
                if (this.mTapToDisconnectView != null) {
                    this.mTapToDisconnectView.setVisibility(0);
                    this.mTapToDisconnectView.setText(R.string.pbl_view_tap_to_disconnect);
                    return;
                }
                return;
            case SMTPMessage.RETURN_HDRS /*2*/:
                if (this.mNameView != null) {
                    this.mNameView.setTextColor(getResources().getColor(R.color.white));
                }
                if (this.mConnectionImage != null) {
                    this.mConnectionImage.setAlpha(1.0f);
                }
                if (this.mTapToDisconnectView == null) {
                    return;
                }
                if (this.mDevice.connectionGoal.equals(ConnectionGoal.DISCONNECT)) {
                    this.mTapToDisconnectView.setVisibility(8);
                    return;
                }
                this.mTapToDisconnectView.setVisibility(0);
                this.mTapToDisconnectView.setText(R.string.pbl_view_text_tap_to_cancel);
                return;
            case ListInfo.INDETERMINATE /*3*/:
                Trace.verbose(TAG, "Unknown device status; treating as disconnected");
                break;
            case SMTPMessage.NOTIFY_DELAY /*4*/:
                break;
            default:
                Trace.error(TAG, "Unsupported status");
                return;
        }
        if (this.mNameView != null) {
            this.mNameView.setTextColor(getResources().getColor(R.color.default_orange_color));
        }
        if (this.mConnectionImage != null) {
            this.mConnectionImage.setAlpha(0.4f);
        }
        if (this.mTapToDisconnectView != null) {
            this.mTapToDisconnectView.setVisibility(8);
        }
    }

    public static Drawable getConnectionDrawableForColor(Context context, PebbleColor color) {
        if (context == null) {
            Trace.warning(TAG, "getConnectionDrawableForColor: context is null");
            return null;
        }
        int drawableId;
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$common$model$PebbleColor[color.ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                drawableId = R.drawable.pebble_model_black_drawer;
                break;
            case SMTPMessage.RETURN_HDRS /*2*/:
                drawableId = R.drawable.pebble_model_white_drawer;
                break;
            case ListInfo.INDETERMINATE /*3*/:
                drawableId = R.drawable.pebble_model_red_drawer;
                break;
            case SMTPMessage.NOTIFY_DELAY /*4*/:
                drawableId = R.drawable.pebble_model_orange_drawer;
                break;
            case R.styleable.WalletFragmentStyle_maskedWalletDetailsHeaderTextAppearance /*5*/:
                drawableId = R.drawable.pebble_model_gray_drawer;
                break;
            case R.styleable.WalletFragmentStyle_maskedWalletDetailsBackground /*6*/:
                drawableId = R.drawable.pebble_model_steel_brushed_drawer;
                break;
            case R.styleable.WalletFragmentStyle_maskedWalletDetailsButtonTextAppearance /*7*/:
                drawableId = R.drawable.pebble_model_steel_matte_drawer;
                break;
            case Response.NO /*8*/:
                drawableId = R.drawable.pebble_model_blue_drawer;
                break;
            case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoTextColor /*9*/:
                drawableId = R.drawable.pebble_model_green_drawer;
                break;
            case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoImageType /*10*/:
                drawableId = R.drawable.pebble_model_pink_drawer;
                break;
            default:
                drawableId = R.drawable.pebble_model_white_drawer;
                break;
        }
        return context.getResources().getDrawable(drawableId);
    }

    public static int getStringForConnectionStatus(PblDeviceRecord device) {
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$common$model$ConnectionStatus[device.connectionStatus.ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                if (device.connectionGoal.equals(ConnectionGoal.DISCONNECT)) {
                    return R.string.connection_manager_disconnecting;
                }
                if (device.isRunningRecoveryFw) {
                    return R.string.connection_manager_connected_prf;
                }
                if (device.recoveryFwVersion == null) {
                    return R.string.connection_manager_connected_no_prf;
                }
                return R.string.connection_manager_connected;
            case SMTPMessage.RETURN_HDRS /*2*/:
                if (device.connectionGoal.equals(ConnectionGoal.DISCONNECT)) {
                    return R.string.connection_manager_disconnecting;
                }
                return R.string.connection_manager_connecting;
            default:
                return R.string.connection_manager_disconnected;
        }
    }

    public static int getTextColourResourceIdForConnectionStatus(PblDeviceRecord device) {
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$common$model$ConnectionStatus[device.connectionStatus.ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                if (device.connectionGoal.equals(ConnectionGoal.DISCONNECT)) {
                    return R.color.white;
                }
                return device.isRunningRecoveryFw ? R.color.menu_item_phone_status_color_red : device.recoveryFwVersion == null ? R.color.menu_item_phone_status_color_red : R.color.menu_item_phone_status_color_green;
            case SMTPMessage.RETURN_HDRS /*2*/:
                return !device.connectionGoal.equals(ConnectionGoal.DISCONNECT) ? R.color.menu_item_phone_status_color_green : R.color.white;
            default:
                return R.color.white;
        }
    }
}
